/*
 * Copyright (c) 2008 James Molloy, Jörg Pfähler, Matthew Iselin
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */
#ifndef MACHINE_MANAGER_H
#define MACHINE_MANAGER_H

#include "Endpoint.h"
#include "ConnectionBasedEndpoint.h"

/**
  * Defines the standard interface for any type of protocol manager object
  * Basically, all protocols have a manager which controls allocation of
  * Endpoints, and also facilitates extra protocol-specific functionality.
  * ALL protocol manager classes must inherit this function and add the
  * relevant getManager() routine to their Endpoint type.
  */
class ProtocolManager
{
    public:
        ProtocolManager()
        {};
        virtual ~ProtocolManager()
        {};
        
        /**
         * The default implementation is quite simple. Individual managers may
         * provide further functionality, they should override this function.
         */
        virtual void returnEndpoint(Endpoint *e)
        {
            e->shutdown(Endpoint::ShutBoth);
            if(e->getType() == Endpoint::ConnectionBased)
            {
                ConnectionBasedEndpoint *ce = static_cast<ConnectionBasedEndpoint *>(e);
                ce->close();
            }
            delete e;
        }
};

#endif

